<?php $c=new c; ?><!DOCTYPE html>
<html lang="<?=$c->lang?>">
  <head>
    <meta charset="<?=$c->encoding?>"> 
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="stylesheet" type="text/css" href="calendar.css">
    <title><?=_('General calendar')?></title>
  </head>
  <body>
    <h1><?=_('Smart calendar')?></h1>
    <article>
      <?php $StartDay0 = new SmartDateTime('Jan 1 previous Monday'); $EndDay = clone $StartDay0; $EndDay->modify('+1 year'); ?>
      <?php for( $day = $StartDay0; $day < $EndDay; ): ?>
      <table>
        <?php $titleday = clone $day; $titleday->modify('+3 weeks') ?>
        <caption><?php printf(_('Calendar: %s'), $titleday->formatYearMonth_l())?></caption>
        <thead>
          <tr>
            <th><?=_('Week')?>
            <?php $Monday0 = new SmartDateTime('Monday'); $Monday1 = clone $Monday0; $Monday1->modify('+1 week'); ?>
            <?php for( $weekday = $Monday0; $weekday < $Monday1; $weekday->modify('+1 day') ): ?>
            <th scope="col"><?=$weekday->formatWeekday_l()?>
            <?php endfor; ?>
        </thead>
        <tfoot></tfoot>
        <tbody>
          <?php $day0 = $day->modify('previous Monday'); $dayx = clone $day0; $dayx->modify('Monday +1 month'); ?>
          <?php for( $day = $day0; $day < $dayx; ): ?>
          <?php $class = $day->is_currentmonday() ? ' class="current"' : ''; ?>
          <tr<?=$class?>>
            <th scope="row"><?=$day->formatWeekNumber_l()?>
            <?php $dayy = clone $day; $dayy->modify('next Monday'); ?>
            <?php for( ; $day < $dayy; $day = $day->modify('+1 day')): ?>
              <?php $class = array($day->format('D'));
                if( $day->is_today() ) $class[]='today';
                if( $r=$day->is_high_day()) { $class[] = 'high'; $class[] = $r; };
                if( $day->is_replaced_day()) $class[] = 'replaced';
                ?>
              <?php $class = implode(' ',$class); $class = ' class="'.$class.'"'; ?>
              <td<?=$class?>><?=strftime('%d',$day->getTimestamp())?>
            <?php endfor; ?>
          <?php endfor; ?>
        </tbody>
      </table>
      <?php endfor; ?>
    </article>
  </body>
</html>
<?php



class c {
  var $encoding = 'utf-8';
  var $lang = 'hu-HU';

  function __construct() {
    require 'SmartDateTime.php'; 
    $this->send_header();
    $this->initialize_gettext();
    date_default_timezone_set('Europe/Budapest');
    SmartDateTime::init($this->lang);
  }

  function initialize_gettext() {
    setlocale(LC_ALL,$this->lang);
    putenv('LC_ALL='.str_replace('-','_',$this->lang));
    bindtextdomain("messages", "./locale");
    textdomain("messages");
    // Translation is looking for in ./locale/hu_HU/LC_MESSAGES/messages.mo now
  }

  function send_header() {
    header('Content-Type: text/html');
    header('Content-Encoding: '.$this->encoding);
    header('Content-Language: '.$this->lang);
  }
  
}


